#include "mmu.h"
#include "command.h"
#include "printk.h"
#include "net.h"
#include "vivi_string.h"

void command_ping(int argc, const char **argv)
{
	if (argc != 2) {
		printk("invalid 'ping' command: wrong arguments\n");
		return;
	}
	NetPingIP = string_to_ip(argv[1]);
	if (NetPingIP == 0) {
		printk("invalid 'ping' command: wrong arguments\n");
		return;
	}

	printk("ping to host %s(0x%x)\n", argv[1], NetPingIP);
	if (NetLoop(PING) < 0) {
		printk("ping failed; host %s is not alive\n", argv[1]);
		return;
	}

	printk("host %s is alive\n", argv[1]);
}


user_command_t ping_cmd = {
	"ping",
	command_ping,
	NULL,
	"ping <addr> \t-- ping to <addr>"
};


void command_led(int argc, const char **argv)
{
    int flag;
    if (strcmp(argv[1], "on") == 0)
        flag = 0x00;
    else
        flag = 0x1e0;
    __asm__ __volatile__(
        "str %0, [%1, #0x00];"
        "mov %0, %2;"
        "str %0, [%1, #0x04];"        
        ::"r"(0x15400), "r"(0x56000010), "g"(flag));
    
}


user_command_t led_cmd = {
	"led",
	command_led,
	NULL,
	"led on/off"
};
